package cn.bdqn.pn.controller.schedule;

import cn.bdqn.pn.pojo.schedule.Seat;
import cn.bdqn.pn.service.schedule.SeatService;
import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.List;

@Controller
@RequestMapping("/seat")
public class SeatController {

    @Autowired
    private SeatService seatService;

    /**
     * 根据场地id查询座位信息
     * @param placeId
     * @return
     */
    @RequestMapping(value = "/findseatInfo")
    @ResponseBody
    public List<Seat> getByPlaceIdFindSeatInfo(@Param("placeId") Integer placeId){
        System.out.println("==============================="+placeId);
        List<Seat> list=null;
        try {
            list=seatService.seatlist(placeId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //System.out.println(JSON.toJSONString(list,true));
        return list;
    }


    /**
     * 修改座位信息
     * @param
     * @param areanum 区数
     * @param iscorridor 是否为走廊
     * @return
     */
    @RequestMapping(value = "/upSeatInfo",method = RequestMethod.POST)
    @ResponseBody
    public boolean upSeatInfo(@Param("array")int[] array,@Param("areanum")String areanum,@Param("iscorridor") Integer iscorridor){
        Seat seat=null;
        boolean falg=false;
        for(int i=0;i<array.length;i++){
            try {
                seat=seatService.findBySeatId(array[i]);
                if(areanum!=null){
                    seat.setAreanum(areanum);
                }
                if(iscorridor!=null){
                    seat.setIscorridor(iscorridor);
                }
                falg=seatService.updateSeatInfo(seat);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(falg){
            return true;
        }else{
            return false;
        }
    }
}
